package com.tianye.salon.controller.admin;

import java.util.Arrays;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.tianye.salon.controller.BaseController;
import com.tianye.salon.model.SalonVipUserTrack;
import com.tianye.salon.service.SalonVipUserTrackService;
import com.tianye.salon.util.CheckUtil;
import com.tianye.salon.util.HttpUtil;


/**
 * SalonVipUserTrack
 * SalonVipUserTrack
 * <p>Title:SalonVipUserTrackController </p>
 * <p>Description:SalonVipUserTrack </p>
 * <p>Company: </p> 
 * @author tianyunyun
 * @date 2017-11-21 13:58:04
 */
@Controller
@RequestMapping(value = "/admin-salonVipUserTrack")
public class SalonVipUserTrackController extends BaseController {
	
	@Autowired
	private SalonVipUserTrackService salonVipUserTrackService;
	
	/**
	 * 跳转到列表页
	* @Title: index 
	* @return    设定文件 
	* @return modelAndView   返回类型 
	* @throws 
	* @author tianyunyun
	* @date 2017-11-21 13:58:04
	 */
	@RequestMapping(value="/index")
	public ModelAndView index(){
		ModelAndView modelAndView = new ModelAndView("/admin/salonvipusertrack_index");
		return modelAndView;
	}
	
	/**
	 * 加载分页数据
	* @Title: ajaxDataList 
	* @param model 实体类
	* @return    设定文件 
	* @return List<SalonVipUserTrack>    返回类型 
	* @throws 
	* @author tianyunyun
	* @date 2017-11-21 13:58:04
	 */
	@RequestMapping(value="/ajaxdataList")
	@ResponseBody
	public Map<String,Object> ajaxDataList(HttpServletRequest request){
		Map param = HttpUtil.getRequestPararms(request);
		try {
			return getPageResult(salonVipUserTrackService, param);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return getFailRtn("加载失败");
	}
	
	/**
	 * 跳转到添加或修改页
	* @Title: index 
	* @Param id 主键id
	* @return    设定文件 
	* @return modelAndView   返回类型 
	* @throws 
	* @author tianyunyun
	* @date 2017-11-21 13:58:04
	 */
	@RequestMapping(value = "/getinfo")
	public ModelAndView getInfo(Integer id,ModelAndView mav) {

		if(!CheckUtil.isEmpty(id)&&id > 0){//修改，查询model
			SalonVipUserTrack model = null;
			try {
				model = salonVipUserTrackService.selectById(id);
			} catch (Exception e) {
				e.printStackTrace();
			}
			mav.addObject("model", model);
			mav.setViewName("/admin/salonvipusertrack_update");
		}else{
			SalonVipUserTrack model = new SalonVipUserTrack();
			mav.addObject("model", model);
			mav.setViewName("/admin/salonvipusertrack_add");
		}
		return mav;
	} 
	
	
	@RequestMapping(value = "/saveorupdate")
	public ModelAndView saveOrUpdate(@ModelAttribute("model") SalonVipUserTrack model,ModelAndView mav) {
		if(null != model && null != model.getId()){
			try {
				salonVipUserTrackService.update(model);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}else{
			try {
				salonVipUserTrackService.insertSelective(model);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		mav.setViewName("redirect:/admin-salonVipUserTrack/index");
		return mav;
	}
	
	
	/**
	 * 删除
	* @Title: saveOrUpdate 
	* @Param model 实体
	* @return    设定文件 
	* @return modelAndView   返回类型 
	* @throws 
	* @author tianyunyun
	* @date 2017-11-21 13:58:04
	 */
	@RequestMapping(value="/ajaxdelete",method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> ajaxDelete(Integer[] ids){
		try {
			salonVipUserTrackService.batchDelete(Arrays.asList(ids));
		} catch (Exception e) {
			e.printStackTrace();
			return getFailRtn("删除失败");
		}
		return getSuccessRtn("","删除成功");
	}
}

